package com.service.Impl;

import java.util.List;

import com.dao.GoodsDao;
import com.domain.Goods;
import com.domain.PageBean;
import com.service.GoodsService;
import com.util.SqlSessionUtils;

public class GoodsServiceImpl implements GoodsService {
	private GoodsDao goodsDao = SqlSessionUtils.getSqlSession().getMapper(GoodsDao.class);
	private int count = 0;


    //分页查询存储
    @Override
    public PageBean findPage(String currentPage,String id) {
        //创建对象调用属性
        PageBean pageBean = new PageBean();

        //设置每页显示的条数
        pageBean.setPages(6);
        //当前的页码
        pageBean.setCurrentPage(Integer.parseInt(currentPage));

        //设置总记录数
        switch (Integer.parseInt(id)) {
            case 1:
                //查询IT技术
                count = goodsDao.count();
                pageBean.setTotalCount(count);
                break;
            case 2:
                //查询小说文学
                count = goodsDao.FictionCount();
                pageBean.setTotalCount(count);
                break;
            case 3:
                //查询历史传记
                count = goodsDao.HistoryCount();
                pageBean.setTotalCount(count);
                break;
            case 4:
                //查询生活
                count = goodsDao.LifeCount();
                pageBean.setTotalCount(count);
                break;
            case 5:
                //查询经营管理
                count = goodsDao.BMCount();
                pageBean.setTotalCount(count);
                break;
            default:
                //查询SF轻小说
                count = goodsDao.SFCount();
                pageBean.setTotalCount(count);
                break;
        }
        //设置总页数
        pageBean.setTotalPages(count%18 == 0?(count/18):(count/18+1));
        //每页的数据和条数
        List<Goods> list = goodsDao.findPage((Integer.parseInt(currentPage)-1)*18, 18,Integer.parseInt(id));
        pageBean.setList(list);
        return pageBean;
    }
	@Override
	public List<Goods> findHot() {
		return goodsDao.findHot();
	}
	
	@Override
	public List<Goods> findHot2() {
		return goodsDao.findHot2();
	}

	@Override
	public List<Goods> findNew() {
		return goodsDao.findNew();
	}

	@Override
	public List<Goods> findNew2() {
		return goodsDao.findNew2();
	}

	@Override
	public Goods findById(int id) {
		return goodsDao.findById(id);
	}

	@Override
	public List<Goods> findLike(String str) {
		return goodsDao.findLike(str);
	}
}
